package com.example.permissionservice.service.impl;

import com.example.permissionservice.service.PermissionService;
import com.example.permissionservice.service.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/permission")
public class PermissionServiceImp implements PermissionService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    @GetMapping("/bindDefaultRole")
    public void bindDefaultRole(Long userId) {
        roleMapper.insert(userId);
    }

    @Override
    @GetMapping("/getUserRoleCode")
    public String getUserRoleCode(Long userId) {
        return roleMapper.select(userId);
    }

    @Override
    @GetMapping("/upgradeToAdmin")
    public void upgradeToAdmin(Long userId) {
        roleMapper.upgrade(userId);
    }

    @Override
    @GetMapping("/downgradeToUser")
    public void downgradeToUser(Long userId) {
        roleMapper.downgrade(userId);
    }
}
